<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>缓存区盘点</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/layui.css"  media="all">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/toastr.min.css"  media="all">
</head>
<body>
<div class="demoTable" style="padding:10px 0 0 15px">
    <div class="layui-inline">
        <input class="layui-input" name="keyword" id="keyword" autocomplete="off" placeholder="请输入配件编号">
    </div>
    <button class="layui-btn layui-btn-blue" style="margin: 0 0 0 10px" data-type="reload"><i class="layui-icon layui-icon-search">  搜索</i></button>
</div>
<table class="layui-hide" id="test" lay-filter="test"></table>
 
<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-blue" lay-event="add"><i class="layui-icon layui-icon-add-1">  盘点</i></button>
		<button class="layui-btn layui-btn-blue" lay-event="add2"><i class="layui-icon layui-icon-add-1">  盘库清空</i></button>
	</div>
</script>          
          
<script src="${pageContext.request.contextPath }/assets/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/layui.all.js"></script>
<script src="${pageContext.request.contextPath }/assets/js/jquery.min.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/js/toastr.min.js" charset="utf-8"></script>
 
<script>
layui.use(['table','layer','upload','form'], function(){
	var table = layui.table;
	var layer = layui.layer,
    form = layui.form;
	
	var $ = layui.jquery, active = {
			reload:function () {
				var keyword = $("#keyword").val();
				console.log(keyword)
				table.reload('contenttable',{
					method:'get',
					where:{panum: keyword}
				});
			}
		}
	$('.layui-btn').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });
	table.render({
	    elem: '#test'
	    ,url:'${pageContext.request.contextPath }/cacheArea/listPageCacheArea.do'
	    ,toolbar: '#toolbarDemo'
	    ,title: '线边库数据表'
	    ,id :'contenttable'
	    ,limits:[10,20,30]
	    ,cols: [[
	      {type: 'checkbox', fixed: 'left'}
	      ,{type: 'numbers', title:'序号', fixed: 'left', width:'5%', unresize: true, sort: true}
	      ,{field:'panum', title:'配件编号'}
	      ,{field:'paname', title:'配件名称'}
	      ,{field:'pamodel', title:'规格型号'}
	      ,{field:'paunit', title:'计量单位'}
	      ,{field:'packNorm', title:'包装规格'}
	      ,{field:'batch', title:'批号'}
	      ,{field:'quantity', title:'账面数量'}
	      ,{field:'reserve1', title:'实际数量', edit: 'text'}
	      ,{field:'reserve2', title:'备注', edit: 'text'}
	      ,{field:'reserve3', title:'盘库清空实际数量', edit: 'text', width: 150}
	      ,{field:'reserve4', title:'备注', edit: 'text'}
	    ]]
	    ,page: true
	});
  
	//头工具栏事件
	table.on('toolbar(test)', function(obj){
		var checkStatus = table.checkStatus(obj.config.id);
	    switch(obj.event){
	    	case 'add':
	    		var data = checkStatus.data;
	    		if (data.length == 0) {
	    			toastr.warning("请至少选择一条记录！");
	        		return false;
				}
	    		$.ajax({
    		    	type:'post',
    		    	url:'${pageContext.request.contextPath }/cacheArea/saveCacheArea.do',
    		    	data:{"list": JSON.stringify(data)},
    		    	success:function(data){
    		    		if(data>0){
    		    			toastr.success("盘点成功！");
    		    			setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
    							//关闭模态框
    							// 父页面刷新
    							window.location.reload();  
    						},2000);
    		    		}else{
    		    			toastr.warning("盘点失败！");
    		    		}
    		    	}
    		    		
    		    })
	      	break;
	    	case 'add2':
	    		var data = checkStatus.data;
	    		if (data.length == 0) {
	    			toastr.warning("请至少选择一条记录！");
	        		return false;
				}
	    		$.ajax({
    		    	type:'post',
    		    	url:'${pageContext.request.contextPath }/cacheArea/saveCacheArea2.do',
    		    	data:{"list": JSON.stringify(data)},
    		    	success:function(data){
    		    		if(data>0){
    		    			toastr.success("盘库清空成功！");
    		    			setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
    							//关闭模态框
    							// 父页面刷新
    							window.location.reload();  
    						},2000);
    		    		}else{
    		    			toastr.warning("盘库清空失败！");
    		    		}
    		    	}
    		    		
    		    })
	      	break;
	    };
	});
});

toastr.options.positionClass = 'toast-top-center'; //提示框的位置设置为中上
</script>

</body>
</html>